package com.zbycorp.generatecode.service.impl;

import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.zbycorp.generatecode.dto.SettingsStorageDTO;
import com.zbycorp.generatecode.service.SettingsStorageService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author YCL
 * @date 2023/3/24
 */
@State(name = "GenerateCodeSetting", storages = @Storage("generateCodeSetting.xml"))
public class SettingsStorageServiceImpl implements SettingsStorageService {

    private SettingsStorageDTO settingsStorage = SettingsStorageDTO.defaultVal();

    @Override
    public @Nullable SettingsStorageDTO getState() {
        return settingsStorage;
    }

    @Override
    public void loadState(@NotNull SettingsStorageDTO state) {
        // 加载配置后填充默认值，避免版本升级导致的配置信息不完善问题
        state.fillDefaultVal();
        this.settingsStorage = state;
    }
}
